package model;

import java.io.File;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.mybeans.factory.BeanTable;

public class Model {
	private EmailDAO emailDAO;
	private UserDAO userDAO;
	private ProductDAO productDAO;
	private TokboxDAO  tokboxDAO;

	public Model(ServletConfig config) throws ServletException {
		try {
			String csvDirStr = config.getInitParameter("csvDir");
			if (csvDirStr != null && csvDirStr.length() > 0) {
				File csvDir = new File(csvDirStr);
				BeanTable.useCSVFiles(csvDir);
			} else {
				String jdbcDriver = config.getInitParameter("jdbcDriverName");
				String jdbcURL = config.getInitParameter("jdbcURL");
				BeanTable.useJDBC(jdbcDriver, jdbcURL);
			}

			emailDAO = new EmailDAO();
			userDAO = new UserDAO();
			productDAO = new ProductDAO();
			tokboxDAO = new TokboxDAO();
			
		} catch (Exception e) {
			throw new ServletException(e);
		}
	}

	
	public EmailDAO getEmailDAO() {
		return emailDAO;
	}
	
	public UserDAO getUserDAO() {
		return userDAO;
	}
	
	public ProductDAO getProductDAO() {
		return productDAO;
	}
	
	public TokboxDAO getTokboxDAO() {
		return tokboxDAO;
	}

}
